﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using AceMobile.Models;

namespace AceMobile.UserControl
{
    public class CustomRoleProvider : RoleProvider
    {
        
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string username)
        {
            //code logic toi csdl để lấy quyền
            MobileWebContext db = new MobileWebContext();//kết nối tới csdl
            var data = (from d in db.Accounts
                        join c in db.Roles on d.Role equals c
                        where d.UserName.Equals(username)
                        select new { Role = c.Name }).ToList();
            //kiem tra neu tim thay tai khoan thi ta gan quyen
            if (data.Count > 0)
            {
                //Nếu tìm thấy thì lấy quyền tương ứng
                return new string[] { data[0].Role };
            }//neu khong tim thay tai khoan trong csdl thi gan cho no quyen la null
            else
                return new String[] { };
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}